<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">

  <title>equal</title>
  <link href="../cppreference.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
  <tr>
  <td>
  <div class="body-content">

  <div class="header-box">
    <a href="../index.html">cppreference.com</a> &gt; <a href=
    "index.html">C++ Algorithms</a> &gt; <a href="equal.html">equal</a>
  </div>

  <div class="name-format">
    equal
  </div>

  <div class="syntax-name-format">
    Syntax:
  </div>
  <pre class="syntax-box">
  #include &lt;algorithm&gt;
  bool equal( iterator start1, iterator end1, iterator start2 );
  bool equal( iterator start1, iterator end1, iterator start2, BinPred p );
</pre>

  <p>The equal() function returns true if the elements in two ranges
  are the same. The first range of elements are those between
  <em>start1</em> and <em>end1</em>. The second range of elements has
  the same size as the first range but starts at <em>start2</em>.</p>

  <p>If the binary predicate <em>p</em> is specified, then it is used
  instead of == to compare each pair of elements.</p>

  <p>For example, the following code uses equal() to compare two
  vectors of integers:</p>
  <pre class="example-code">
 vector&lt;int&gt; v1;
 for( int i = 0; i &lt; 10; i++ ) {
   v1.push_back( i );
 }              

 vector&lt;int&gt; v2;
 for( int i = 0; i &lt; 10; i++ ) {
   v2.push_back( i );
 }              

 if( equal( v1.begin(), v1.end(), v2.begin() ) ) {
   cout &lt;&lt; &quot;v1 and v2 are equal&quot; &lt;&lt; endl;
 } else {
   cout &lt;&lt; &quot;v1 and v2 are NOT equal&quot; &lt;&lt; endl;
 }              
</pre>

  <div class="related-name-format">
    Related topics:
  </div>

  <div class="related-content">
    <a href="find_if.html">find_if</a><br>
    <a href=
    "lexicographical_compare.html">lexicographical_compare</a><br>
    <a href="mismatch.html">mismatch</a><br>
    <a href="search.html">search</a>
  </div>
  </div>
  </td>
  


  </tr>
  </table>
</body></html>
